home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Utilities / ODDesUtl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  3.2 KB  |  152 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODDesUtl.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>    .03.1996    NP        Added debugging code (turned off).
  13.  
  14.     To Do:
  15. */
  16.  
  17. /*
  18.     File:        ODDesUtl.cpp
  19.  
  20.     Contains:    Implementation of ODDesc<->AEDesc conversion utilities
  21.  
  22.     Owned by:    Nick Pilch
  23.  
  24.     Copyright:    © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
  25.  
  26.     
  27. */
  28.  
  29. #ifndef _ODDEBUG_
  30. #include "ODDebug.h"
  31. #endif
  32.  
  33. #ifndef _ODMEMORY_
  34. #include <ODMemory.h>
  35. #endif
  36.  
  37. #ifndef _EXCEPT_
  38. #include "Except.h"
  39. #endif
  40.  
  41. #ifndef _ODDESUTL_
  42. #include <ODDesUtl.h>
  43. #endif
  44.  
  45. #ifndef SOM_ODDesc_xh
  46. #include "ODDesc.xh"
  47. #endif
  48.  
  49. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  50. #include "ODRgstry.xh"
  51. #endif
  52.  
  53. #ifndef _BARRAY_
  54. #include "BArray.h"
  55. #endif
  56.  
  57. #ifndef SOMCorba_h
  58. #include "somcorba.h"
  59. #endif
  60.  
  61.  
  62. //------------------------------------------------------------------------------
  63. // ODDescToAEDesc
  64. //------------------------------------------------------------------------------
  65.  
  66. ODError ODDescToAEDesc(ODDesc* odDesc, AEDesc* aeDesc)
  67. {
  68.     ODError            error = noErr;
  69.     Environment*    ev = somGetGlobalEnvironment();
  70.     ODDescType        descType = odDesc->GetDescType(ev);
  71.     const DescType    randomDescType = 'nick';
  72.  
  73.     TRY
  74.         ODByteArray    data;
  75.  
  76.         if (descType == typeNull)
  77.         {
  78.             aeDesc->dataHandle = kODNULL;
  79.             aeDesc->descriptorType = typeNull;
  80.         }
  81.         else
  82.         {
  83.             data = odDesc->GetRawData(ev);
  84.             // CAREFUL HERE! IF YOU CALL AECreateDesc USING typeAEList OR
  85.             //    typeAERecord, IT WILL STICK A HEADER ON THE DESCRIPTOR FOR YOU.
  86.             //    THAT'S NOT WHAT YOU WANT IN THIS CASE BECAUSE THE ODDESC ALREADY
  87.             //    CONTAINS ALL THE RAW DATA INCLUDING THE HEADER. WORK AROUND
  88.             //    BY CREATING DESCRIPTOR WITH RANDOM TYPE AND SETTING THE DescType
  89.             //    AFTERWORDS.
  90.             THROW_IF_ERROR(AECreateDesc(randomDescType,
  91.                                         data._buffer, data._length, aeDesc));
  92.             aeDesc->descriptorType = odDesc->GetDescType(ev);
  93.             DisposeByteArrayStruct(data);
  94.         }
  95.     CATCH_ALL
  96.         error = ErrorCode();
  97.     ENDTRY
  98.     
  99.     return error;
  100. }
  101.  
  102. //------------------------------------------------------------------------------
  103. // AEDescToODDesc
  104. //------------------------------------------------------------------------------
  105.  
  106. ODError AEDescToODDesc(AEDesc* aeDesc, ODDesc* odDesc)
  107. {
  108.     ODError            error = noErr;
  109.     Environment*    ev = somGetGlobalEnvironment();
  110.     Handle            dataHandle = aeDesc->dataHandle;
  111.     ODDescType        descType = aeDesc->descriptorType;
  112.  
  113. #define DEBUGGING_ODDESC_LEAKS 0
  114. #if DEBUGGING_ODDESC_LEAKS
  115.     if (odDesc->GetDescType(ev) == typeUserToken)
  116.         WARN("You are writing into a token, possibly overwriting an ODDesc*.");
  117. #endif
  118.     
  119.     TRY
  120.         ODByteArray        data;
  121.         unsigned long    dataSize;
  122.  
  123.         if (dataHandle != kODNULL)
  124.         {
  125.             dataSize = ODGetHandleSize(dataHandle);
  126.             data._buffer = (octet*)ODNewPtr(dataSize);
  127.             ODBlockMove(*(dataHandle), data._buffer, dataSize);
  128.             data._length = dataSize;
  129.             data._maximum = dataSize;
  130.     
  131.             odDesc->SetRawData(ev, &data);
  132.  
  133.             DisposeByteArrayStruct(data);
  134.         }
  135.         odDesc->SetDescType(ev, descType);
  136.  
  137.     CATCH_ALL
  138.         error = ErrorCode();
  139.     ENDTRY
  140.     
  141.     return error;
  142. }
  143. #if 0
  144. ODError AEDescChanged(AEDesc* aeDesc, ODDesc* odDesc)
  145. {
  146. //    AEDesc* desc = odDesc->GetAEDesc(somGetGlobalEnvironment());
  147. //    WASSERT( desc );
  148. //    *desc = *aeDesc;
  149.     return noErr;
  150. }
  151. #endif /* 0 */
  152.